//
//  ViewController.m
//  hello
//
//  Created by 查传申 on 15/11/12.
//  Copyright © 2015年 查传申. All rights reserved.
//

#import "ViewController.h"
#import "NAvAViewController.h"
#import "TitleselectButton.h"
#import "Select_listTableView.h"
#import "BackSelectWindow.h"
#import "NewView.h"
@interface ViewController ()<UITextFieldDelegate,UITextViewDelegate>{
    NSString *aa;
    NSMutableAttributedString *string;
    UIImageView *imageView_o;
}
@property(strong,nonatomic)NewView *Vv;
@end

@implementation ViewController
-(void)change:(TitleselectButton *)btn{
//    [btn setTitle:@"lsfjslkfjdlk" forState:UIControlStateNormal];
    btn.label_title.text = @"asdweqweqwewqewqeasdsad";
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    离开就离开就离开
//    离开离开就离开就离开啊实打实大师的
//    是非得失发生地方
//    的是非得失
    self.view.backgroundColor = [UIColor redColor];
    
    
    TitleselectButton *btn = [[TitleselectButton alloc]initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 30)];
    [btn setTitle:@"" forState:UIControlStateNormal];
    btn.label_title.text = @"asdasdsad";
    [btn addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside];
    btn.label_title.backgroundColor = [UIColor cyanColor];
    btn.imageV.backgroundColor = [UIColor redColor];
    btn.backgroundColor = [UIColor purpleColor];
    
    [self.view addSubview:btn];
    
    UIView *view_back = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(btn.frame), self.view.frame.size.width, self.view.frame.size.height)];
    view_back.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.9];
    view_back.hidden = NO;
    [self.view addSubview:view_back];
    
    Select_listTableView *tableSelect = [[Select_listTableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - CGRectGetMaxY(btn.frame)-100) style:UITableViewStylePlain Arr: nil number:0];
    tableSelect.alpha = 1;
    [view_back addSubview:tableSelect];
    
    
//    _Vv = [[[NSBundle mainBundle]loadNibNamed:@"NewView" owner:nil options:nil] objectAtIndex:0];
    
    
//    //    navgationView = [[[NSBundle mainBundle] loadNibNamed:@"UserCenterNavgationView" owner:nil options:nil] objectAtIndex:0];
////    _Vv.frame = CGRectMake(0, 0, self.view.frame.size.width, 88);
//    //    navgationView.delegate = self;
//    
//    
//    //    View.backgroundColor = [UIColor purpleColor];
//    [self.view addSubview:_Vv];

    
    
//    UITextField * text_money = [[UITextField alloc]initWithFrame:CGRectMake(10, 30, (self.view.frame.size.width - 30)/3, 20)];
//    text_money.tag = 1000;
//    text_money.placeholder = @"输入自定义数量";
//    text_money.delegate = self;
//    text_money.backgroundColor = [UIColor blueColor];
//    [self.view addSubview:text_money];
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didchanzhi:) name:UITextFieldTextDidChangeNotification object:nil];
    
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
//    [button addTarget:self action:@selector(uuu) forControlEvents:UIControlEventTouchUpInside];
//    button.backgroundColor = [UIColor redColor];
//    button.frame = CGRectMake(10, 100, 50, 50);
//    [self.view addSubview:button];
//    
//    
//    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//    NSString *testStr = [defaults objectForKey:@"vvf"];
//    if (testStr == nil) {
//        [defaults setObject:@"555" forKey:@"vvf"];
//        [defaults synchronize];
//        testStr =  [defaults objectForKey:@"vvf"];
//
//    }
//    NSLog(@"testStr is: %@",testStr);
//    UITextField *textfiled = [[UITextField alloc]initWithFrame:CGRectMake(10, 70, 100, 20)];
//    textfiled.userInteractionEnabled = NO;
//    textfiled.tag = 10000;
//    textfiled.backgroundColor = [UIColor purpleColor];
//    [self.view addSubview:textfiled];
//88888888888888888888888888
//    UITextView *label = [[UITextView alloc]initWithFrame:CGRectMake(10, 70, 300, 300)];
//    label.backgroundColor = [UIColor purpleColor];
//    label.tag = 1111;
//    label.delegate =self;
//    [self.view addSubview:label];
//    
//    string=[[NSMutableAttributedString alloc]initWithString:label.text];
//
////   label.attributedText = string;
//    
//    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(10, 400, 30, 20)];
//    [button addTarget:self
//               action:@selector(kakaka) forControlEvents:UIControlEventTouchUpInside];
//    button.backgroundColor = [UIColor redColor];
//    [self.view addSubview:button];
//    NSMutableAttributedString *stt = [[NSMutableAttributedString alloc]initWithString:@"asdasda"];
//    [stt addAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} range:NSMakeRange(0, stt.length)];
//    NSString *stttt = [NSString stringWithFormat:@"%@",stt];
//    NSMutableAttributedString *as = (NSMutableAttributedString *)stttt;
//    NSLog(@"%@\n%@\n%@",stt,stttt,as);
    
    
    
    
    
    
//    NSData
//    imageView_o = [[UIImageView alloc]init];
//    imageView_o.backgroundColor = [UIColor redColor];
//    imageView_o.image = [UIImage imageNamed:@"6666.jpg"];
//    imageView_o.userInteractionEnabled = YES;
////    imageView_o.contentMode = UIViewContentModeScaleAspectFit;
//    imageView_o.autoresizesSubviews = YES;
////    imageView_o.autoresizingMask =
////    UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
//    CGFloat h = 100/imageView_o.image.size.width*imageView_o.image.size.height;
//    imageView_o.frame = CGRectMake(100, 400, 100, h);
//    UILongPressGestureRecognizer *longges = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longtap_down:)];
//    [imageView_o addGestureRecognizer:longges];
//    [self.view addSubview:imageView_o];
}
-(void)longtap_down:(UILongPressGestureRecognizer *)longtap{
    if (longtap.state == UIGestureRecognizerStateBegan) {
        UIImageView *image_v = (UIImageView *)longtap.view;
        UIImageView *image = [[UIImageView alloc]init];
        image.tag = 1237;
        image.image = image_v.image;
        
        UIAlertView *tip = [[UIAlertView alloc]initWithTitle:@"" message:@"保存图片" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        tip.tag = 1236;
        [tip show];
        
        
    }
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == 1236) {
        if (buttonIndex == 1) {
            UIImageView *imageV  = (UIImageView *)[self.view viewWithTag:1237];
//            imageV.image = [UIImage imageNamed:@"stay_03.png"];
            UIImageWriteToSavedPhotosAlbum([imageView_o image], nil, nil,nil);
            //            UIImageView *bb = [[UIImageView alloc]initWithFrame:CGRectMake(0, 100, 100, 100)];
            //            bb.image = imageV.image;
            //            bb.backgroundColor = [UIColor redColor];
            //            [self.view addSubview:bb];
            
        }
    }
}

-(void)kakaka{
    
    UITextView *label = (UITextView *)[self.view viewWithTag:1111];

    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil] ;
    
    textAttachment.image = [UIImage imageNamed:@"22.jpg"]; //要添加的图片
    
    NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment] ;
    

        [string insertAttributedString:[[NSMutableAttributedString alloc]initWithString:@"\n"] atIndex:string.length];
    [string insertAttributedString:textAttachmentString atIndex:string.length ];//index为用户指定要插入图片的位置
    [string insertAttributedString:[[NSMutableAttributedString alloc]initWithString:@"\n"] atIndex:string.length];
//    UIImage *
    NSLog(@"%@,%ld,%@",label.text,string.length,string);
    label.attributedText = string;

}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
//    NSLog(@"%@",text);
    if ([text isEqualToString:@""]&&string.length>0) {
        [string deleteCharactersInRange:NSMakeRange(string.length-1, 1)];
    }else{
        [string insertAttributedString:[[NSMutableAttributedString alloc]initWithString:text] atIndex:string.length];
    }
    return YES;
}
//88888888888888888888888888888888888
-(void)didchanzhi:(NSNotification *)noty{
//    NSLog(@"%@",noty.userInfo);
}
-(void)uuu{
    UITextField *tt = (UITextField *)[self.view viewWithTag:10000];
    tt.userInteractionEnabled = YES;
    [tt becomeFirstResponder];
    NSLog(@"%@",tt);
}
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
